package com.ibeeking.found.content.api.feign.fallback;

import com.ibeeking.found.content.api.feign.ContentMemberBClient;
import com.ibeeking.found.content.api.common.dto.MemberInfoDTO;
import com.ibeeking.nematos.utils.data.Collections3;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class ContentMemberBFallbackFactory implements FallbackFactory<ContentMemberBClient> {
    @Override
    public ContentMemberBClient create(Throwable throwable) {
        return new ContentMemberBClient() {

            @Override
            public ResponseResult<List<MemberInfoDTO>> infoList(Set<Long> ids) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，通过会员id查询会员信息失败。" + throwable.getMessage(), Collections3.emptyList());
            }

            @Override
            public ResponseResult<List<Long>> allMemberId() {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "查询全部会员id失败。" + throwable.getMessage(), Collections3.emptyList());
            }

            @Override
            public ResponseResult<List<Long>> queryMemberIdsByPhoneLike(String phone) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "根据手机号模糊查询会员id失败。" + throwable.getMessage(), Collections3.emptyList());
            }
        };
    }
}
